package org.qydjk.common.util;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;

/**
 * 阿里企业邮箱发
 */
public class AliMailUtil {

    private static void sendAliMail(String to, String other, String subject,String content) throws AddressException,MessagingException{
        Properties prop=new Properties();
        prop.put("mail.host","smtp.mxhichina.com" );
        //个人邮箱
        //prop.put("mail.host","smtp.aliyun.com" );
        prop.put("mail.transport.protocol", "smtp");
        prop.put("mail.smtp.auth", "true");

        //使用java发送邮件5步骤
        //1.创建sesssion
        Session session = Session.getInstance(prop);
        //开启session的调试模式，可以查看当前邮件发送状态
        session.setDebug(true);

        //2.通过session获取Transport对象（发送邮件的核心API）
        Transport ts = session.getTransport();
        //3.通过邮件用户名密码链接，阿里云默认是开启个人邮箱pop3、smtp协议的，所以无需在阿里云邮箱里设置
        ts.connect("wx@qypaas.com", "Wangxiao01");

        //创建邮件对象
        MimeMessage mm = new MimeMessage(session);
        //设置发件人
        mm.setFrom(new InternetAddress("wx@qypaas.com"));
        //设置收件人
        mm.setRecipient(Message.RecipientType.TO, new InternetAddress(to));
        //设置抄送人
        mm.setRecipient(Message.RecipientType.CC, new InternetAddress(other));

        mm.setSubject(subject);
        mm.setContent(content, "text/html;charset=utf-8");
        //5.发送电子邮件

        ts.sendMessage(mm, mm.getAllRecipients());
    }

    public static void main(String[] args) throws MessagingException {
        String cc = "<p>\n" +
                "    百度为您找到相关结果约449,000个\n" +
                "</p>\n" +
                "<h3 class=\"t\" style=\"margin: 0px 0px 1px; padding: 0px; list-style: none; font-weight: 400; font-size: medium; line-height: 1.54;\">\n" +
                "    <a href=\"https://www.baidu.com/link?url=6ByIR_JCwuQwl-oAlR6Na0dbcXlOvcDlBe87wGWqU-vuDeTmiUBDhcOL83nHxvuj&wd=&eqid=f255e39000027eab0000000459f6f388\" target=\"_blank\"><span style=\"color: rgb(204, 0, 0);\">百度</span>ueditor<span style=\"color: rgb(204, 0, 0);\">编辑器</span>&nbsp;- UEditor - 首页</a>\n" +
                "</h3>\n" +
                "<p>\n" +
                "    UEditor 是一套开源的在线HTML<span style=\"color: rgb(204, 0, 0);\">编辑器</span>,主要用于让用户在网站上获得所见即所得编辑效果,开发人员可以用 UEditor 把传统的多行<span style=\"color: rgb(204, 0, 0);\">文本</span>输入框(textarea)替换为可视化的富...\n" +
                "</p>\n" +
                "<p>\n" +
                "    <a target=\"_blank\" href=\"http://www.baidu.com/link?url=6ByIR_JCwuQwl-oAlR6Na0dbcXlOvcDlBe87wGWqU-vuDeTmiUBDhcOL83nHxvuj\" class=\"c-showurl\" style=\"color: green; text-decoration-line: none;\">ueditor.baidu.com/&nbsp;</a>\n" +
                "</p>\n" +
                "<p>\n" +
                "    <span class=\"c-icon c-icon-triangle-down-g\" style=\"background: url(&quot;https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/global/img/icons_5859e57.png&quot;) -744px -144px no-repeat; display: inline-block; width: 14px; height: 14px; vertical-align: text-bottom; overflow: hidden; cursor: pointer;\"></span>\n" +
                "</p>\n" +
                "<p>\n" +
                "    <span class=\"c-icons-outer\" style=\"overflow: hidden; display: inline-block; vertical-align: bottom;\"><span class=\"c-icons-inner\" style=\"margin-left: -4px;\"><span class=\"c-vline\" style=\"display: inline-block; margin: 0px 3px; border-left: 1px solid rgb(221, 221, 221); width: 0px; height: 12px;\"></span><span class=\"c-trust-as vstar \"><a href=\"https://www.baidu.com/s?wd=%E5%8C%97%E4%BA%AC%E7%99%BE%E5%BA%A6%E7%BD%91%E8%AE%AF%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8@v&vmp_ec=1db98727b459e9b6b52ead16833c2Z2tYHIZpJ5bfX4e8aUa92f93uFYb87m5VuGl5d3d09l13aX4se5311df5d5&vmp_ectm=1504150618&from=vs&product=v&rsv_dl=0_left_v_3\" class=\"c-icon c-icon-v c-icon-v3\" target=\"_blank\" style=\"background: url(&quot;https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/global/img/icons_5859e57.png&quot;) -936px -192px no-repeat; display: inline-block; width: 19px; height: 14px; vertical-align: text-bottom; overflow: hidden; border: 1px solid transparent; cursor: pointer;\"></a></span></span></span>&nbsp;-&nbsp;<a href=\"http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece763105180304212dd232bd7a7452c8fc50f84642c101a39feaf627f5052dcd20c6516d9424b9af421033d1421c78cb8825dadcb85295f9f5643676d805662d00edfbc5124b137e059fed81bf0ca8125e0d8c5d2af4322ce44717f&p=926df915d9c040a84bfbd42d021482&newp=86759a46d7c416f546b68a2d02149e231610db2151d6d7136b82c825d7331b001c3bbfb42324150fd2ce7f6401ad495eeaf432713d092ba3dda5c91d9fb4c57479df7d2a2b02&user=baidu&fm=sc&query=%B0%D9%B6%C8%B8%BB%CE%C4%B1%BE%B1%E0%BC%AD%C6%F7&qid=f255e39000027eab&p1=1\" target=\"_blank\" class=\"m\" style=\"color: rgb(102, 0, 102);\">百度快照</a><span class=\"c-pingjia\">&nbsp;-&nbsp;<a href=\"https://www.baidu.com/tools?url=http%3A%2F%2Fwww.baidu.com%2Flink%3Furl%3D6ByIR_JCwuQwl-oAlR6Na0dbcXlOvcDlBe87wGWqU-vuDeTmiUBDhcOL83nHxvuj&jump=https%3A%2F%2Fkoubei.baidu.com%2Fp%2Fsentry%3Ftitle%3D%02%E7%99%BE%E5%BA%A6%03ueditor%02%E7%BC%96%E8%BE%91%01%E5%99%A8%03%20-%20%01UEditor%01%20%01-%01%20%01%E9%A6%96%E9%A1%B5%01%26q%3D%E7%99%BE%E5%BA%A6%E5%AF%8C%E6%96%87%E6%9C%AC%E7%BC%96%E8%BE%91%E5%99%A8%26from%3Dps_pc3&key=surl\" target=\"_blank\" class=\"m\" style=\"color: rgb(102, 0, 102);\">90%好评</a></span>\n" +
                "</p>\n" +
                "<p>\n" +
                "    <a href=\"http://ueditor.baidu.com/website/download.html\" target=\"_blank\" style=\"font-size: 1.1em; position: relative;\">ueditor编辑器</a>\n" +
                "</p>\n" +
                "<p class=\"m\" style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; list-style: none; color: rgb(102, 102, 102);\">\n" +
                "    UEditor 是一套开源的在线HTML编辑器,主要用于让用户在网站上获得所见即\n" +
                "</p>\n" +
                "<p>\n" +
                "    <a href=\"http://ueditor.baidu.com/doc/\" target=\"_blank\" style=\"font-size: 1.1em; position: relative;\">api文档</a>\n" +
                "</p>\n" +
                "<p class=\"m\" style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; list-style: none; color: rgb(102, 102, 102);\">\n" +
                "    2013年8月30日 - UEditor API (适用于1.2.6.1+)命令列表COMMAND通用方法\n" +
                "</p>\n" +
                "<p>\n" +
                "    <a href=\"http://ueditor.baidu.com/website/index.html\" target=\"_blank\" style=\"font-size: 1.1em; position: relative;\">百度editor</a>\n" +
                "</p>\n" +
                "<p class=\"m\" style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; list-style: none; color: rgb(102, 102, 102);\">\n" +
                "    UEditor是由百度web前端研发部开发所见即所得富文本web编辑器,具有轻量,\n" +
                "</p>\n" +
                "<p>\n" +
                "    <a href=\"http://ueditor.baidu.com/website/umeditor.html\" target=\"_blank\" style=\"font-size: 1.1em; position: relative;\">umeditor使用</a>\n" +
                "</p>\n" +
                "<p class=\"m\" style=\"margin-top: 0px; margin-bottom: 0px; padding: 0px; list-style: none; color: rgb(102, 102, 102);\">\n" +
                "    UEditor是百度的一个javascript编辑器的开源项目,能带给您良好的富文本使\n" +
                "</p>\n" +
                "<h3 class=\"t\" style=\"margin: 0px 0px 1px; padding: 0px; list-style: none; font-weight: 400; font-size: medium; line-height: 1.54;\">\n" +
                "    <a href=\"http://www.baidu.com/link?url=zxr6F8KWMhrLEf2WT-vZdXLNktj6JLNvtpdl4O-br_5238hzj7L_tvdFK46fI9t8rvWQm2I_WAm3JHITuoJ5bq\" target=\"_blank\"><span style=\"color: rgb(204, 0, 0);\">百度编辑器</span>官网demo - UEditor - 示例</a>\n" +
                "</h3>\n" +
                "<p>\n" +
                "    UEditor是<span style=\"color: rgb(204, 0, 0);\">百度</span>的一个javascript<span style=\"color: rgb(204, 0, 0);\">编辑器</span>的开源项目,能带给您良好的<span style=\"color: rgb(204, 0, 0);\">富文本</span>使用体验...&nbsp;<span style=\"color: rgb(204, 0, 0);\">百度</span>doc 测试版已上线,欢迎试用和反馈!语言...隐藏<span style=\"color: rgb(204, 0, 0);\">编辑器</span>&nbsp;显示<span style=\"color: rgb(204, 0, 0);\">编辑器</span>&nbsp;设置<span style=\"color: rgb(204, 0, 0);\">编辑器</span>的...\n" +
                "</p>\n" +
                "<p>\n" +
                "    <a target=\"_blank\" href=\"http://www.baidu.com/link?url=zxr6F8KWMhrLEf2WT-vZdXLNktj6JLNvtpdl4O-br_5238hzj7L_tvdFK46fI9t8rvWQm2I_WAm3JHITuoJ5bq\" class=\"c-showurl\" style=\"color: green; text-decoration-line: none;\">ueditor.baidu.com/webs...&nbsp;</a>\n" +
                "</p>\n" +
                "<p>\n" +
                "    <span class=\"c-icon c-icon-triangle-down-g\" style=\"background: url(&quot;https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/global/img/icons_5859e57.png&quot;) -744px -144px no-repeat; display: inline-block; width: 14px; height: 14px; vertical-align: text-bottom; overflow: hidden; cursor: pointer;\"></span>\n" +
                "</p>\n" +
                "<p>\n" +
                "    <span class=\"c-icons-outer\" style=\"overflow: hidden; display: inline-block; vertical-align: bottom;\"><span class=\"c-icons-inner\" style=\"margin-left: -4px;\"><span class=\"c-vline\" style=\"display: inline-block; margin: 0px 3px; border-left: 1px solid rgb(221, 221, 221); width: 0px; height: 12px;\"></span><span class=\"c-trust-as vstar \"><a href=\"https://www.baidu.com/s?wd=%E5%8C%97%E4%BA%AC%E7%99%BE%E5%BA%A6%E7%BD%91%E8%AE%AF%E7%A7%91%E6%8A%80%E6%9C%89%E9%99%90%E5%85%AC%E5%8F%B8@v&vmp_ec=1db98727b459e9b6b52ead16833c2Z2tYHIZpJ5bfX4e8aUa92f93uFYb87m5VuGl5d3d09l13aX4se5311df5d5&vmp_ectm=1504150618&from=vs&product=v&rsv_dl=0_left_v_3\" class=\"c-icon c-icon-v c-icon-v3\" target=\"_blank\" style=\"background: url(&quot;https://ss1.bdstatic.com/5eN1bjq8AAUYm2zgoY3K/r/www/cache/static/protocol/https/global/img/icons_5859e57.png&quot;) -936px -192px no-repeat; display: inline-block; width: 19px; height: 14px; vertical-align: text-bottom; overflow: hidden; border: 1px solid transparent; cursor: pointer;\"></a></span></span></span>&nbsp;-&nbsp;<a href=\"http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece763105180304212dd232bd7a7452c8fc50f84642c101a39fefe7072515f9592613a5df11200bda6612d6a1420c0c18ed714c9fecf6879873044720bf04a05a31db8ba4c32c050872ae3b86997adf14284dfa5c4ae5244ba50120af7e78a2a1764c97887162693d78e3b634811cafa4161e82d72&p=926df915d9c041a84bfbd42d021482&newp=86759a46d6c416f546b68a2d02149e231610db2151d1d701298ffe0cc4241a1a1a3aecbf21271b01d5c47a6704aa435ee8f33c71320634f1f689df08d2ecce7e78d2396f6e&user=baidu&fm=sc&query=%B0%D9%B6%C8%B8%BB%CE%C4%B1%BE%B1%E0%BC%AD%C6%F7&qid=f255e39000027eab&p1=2\" target=\"_blank\" class=\"m\" style=\"color: rgb(102, 0, 102);\">百度快照</a>\n" +
                "</p>\n" +
                "<p>\n" +
                "    <br/>\n" +
                "</p>";
        sendAliMail("862530928@qq.com","1015727960@qq.com","体检通知1",cc);
    }
}
